import { SAVE_TOKEN, REMOVE_TOKEN } from '../../utils/constant'
import { setItem, removeItem } from '../../utils/storage'
import { TOKEN } from '../../utils/constant'

// 用户登录后，将用户信息存入容器
export const loginAsync = data => {
    return (dispatch) => {
        setItem(TOKEN, data.token)
        dispatch({type:SAVE_TOKEN, data})
    }
}

// 退出登录，销毁token
export const logoutAsync = data => {
    return (dispatch) => {
        removeItem(TOKEN)
        dispatch({type:REMOVE_TOKEN, data})
    }
}